package com.example.androidlearning2200.frg;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.androidlearning2200.R;
import com.example.androidlearning2200.adapter.NewsAdapter;
import com.example.androidlearning2200.bean.NewsBean;

import java.util.ArrayList;
import java.util.List;

public class MsgFragment extends Fragment {

    private RecyclerView rvNews;
    private List<NewsBean> datas = new ArrayList<>();


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_msg, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        rvNews = view.findViewById(R.id.rvNews);
        loadDataByNewsType();
        rvNews.setLayoutManager(new LinearLayoutManager(getContext()));
        rvNews.setAdapter(new NewsAdapter(datas) {
            @Override
            public void clickItem(int position) {

            }
        });
    }

    /**
     * 准备数据
     */
    private void loadDataByNewsType() {
        datas.clear();
        datas.add(new NewsBean("明学昌、明珍珍、明国平三名缅北电诈重要头目被缅甸警方逮捕", "光明网", 20, "2天前", R.mipmap.welcome1));
        datas.add(new NewsBean("法治课｜我国警方通缉的缅甸明氏家族电诈头目3人移交我方，他们将受到怎样的制裁", "海报新闻", 20, "2天前", R.mipmap.welcome1));
        datas.add(new NewsBean("刘涛、李湘、陈赫已停播，大批艺人明星退出直播间", "八卦王", 20, "2天前", R.mipmap.welcome1));
    }

}
